home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / AX25.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-14  |  9.5 KB  |  314 lines

  1.  /* Mods by G1EMM */
  2. #ifndef    _AX25_H
  3. #define    _AX25_H
  4.  
  5. #ifndef    _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.  
  9. #ifndef _IP_H
  10. #include "ip.h"
  11. #endif
  12.  
  13. #ifndef    _MBUF_H
  14. #include "mbuf.h"
  15. #endif
  16.  
  17. #ifndef    _IFACE_H
  18. #include "iface.h"
  19. #endif
  20.  
  21. #ifndef    _SOCKADDR_H
  22. #include "sockaddr.h"
  23. #endif
  24.  
  25.  
  26. /* AX.25 datagram (address) sub-layer definitions */
  27.  
  28. #define    MAXDIGIS    7    /* Maximum number of digipeaters */
  29. #define    ALEN        6    /* Number of chars in callsign field */
  30. #define    AXALEN        7    /* Total AX.25 address length, including SSID */
  31. #define    AXBUF        10    /* Buffer size for maximum-length ascii call */
  32.  
  33.  
  34. #ifndef _LAPB_H
  35. #include "lapb.h"
  36. #endif
  37.  
  38. /* Bits within SSID field of AX.25 address */
  39. #define    SSID        0x1e    /* Sub station ID */
  40. #define    REPEATED    0x80    /* Has-been-repeated bit in repeater field */
  41. #define    E        0x01    /* Address extension bit */
  42. #define    C        0x80    /* Command/response designation */
  43. #define AXN        0x20    /* Supports AX25 L2 negotiations */
  44. #define Q        0x40    /* AX25 negotiation request/response */
  45.  
  46. #define DIGI_IDS    "+?#-"
  47.  
  48. /* Our AX.25 address */
  49. extern char Mycall[AXALEN];
  50. extern char AXuser[AXALEN];
  51. extern char NOCALL[AXALEN];
  52.  
  53.  
  54. /* List of AX.25 multicast addresses, e.g., "QST   -0" in shifted ASCII */
  55. extern char Ax25multi[][AXALEN];
  56. #define QSTCALL 0
  57. #define NODESCALL 1
  58. #define MAILCALL 2
  59. #define IDCALL 3
  60. /*currently not used in this code*/
  61. #define OPENCALL 4
  62. #define CQCALL 5
  63. #define BEACONCALL 6
  64. #define RMNCCALL 7
  65. #define ALLCALL 8
  66.  
  67.  
  68. /* Number of chars in interface field. The involved definition takes possible
  69.  * alignment requirements into account, since ax25_addr is of an odd size.
  70.  */
  71. #define    ILEN    (sizeof(struct sockaddr) - sizeof(short) - AXALEN)
  72.  
  73. /* Socket address, AX.25 style */
  74. struct sockaddr_ax {
  75.     short sax_family;        /* 2 bytes */
  76.     char ax25_addr[AXALEN];
  77.     char iface[ILEN];        /* Interface name */
  78. };
  79.  
  80. /* Internal representation of an AX.25 header */
  81. struct ax25 {
  82.     char dest[AXALEN];        /* Destination address */
  83.     char source[AXALEN];        /* Source address */
  84.     char digis[MAXDIGIS][AXALEN];    /* Digi string */
  85.     int ndigis;            /* Number of digipeaters */
  86.     int nextdigi;            /* Index to next digi in chain */
  87.     int cmdrsp;            /* Command/response */
  88. };
  89.  
  90. /* C-bit stuff */
  91. #define    LAPB_UNKNOWN        0
  92. #define    LAPB_COMMAND        1
  93. #define    LAPB_RESPONSE        2
  94.  
  95. /* AX.25 routing table entry */
  96. struct ax_route {
  97.     struct ax_route *next;        /* Linked list pointer */
  98.     char target[AXALEN];
  99.     struct iface *iface;
  100.     char digis[MAXDIGIS][AXALEN];
  101.     int ndigis;
  102.     char type;
  103. #define AX_NONSETUP    0        /* used to request a non-setup route */
  104. #define    AX_LOCAL    1        /* Set by local ax25 route command */
  105. #define    AX_AUTO        2        /* Set by incoming packet */
  106. #define AX_SETUP    4        /* Used for overriding auto entries */
  107.     char mode;            /* Connection mode (G1EMM) */
  108. #define    AX_DEFMODE    0        /* Use default interface mode */
  109. #define    AX_VC_MODE    1        /* Try to use Virtual circuit */
  110. #define    AX_DATMODE    2        /* Try to use Datagrams only */
  111. };
  112. #define NULLAXR    ((struct ax_route *)0)
  113.  
  114. extern struct ax_route *Ax_routes;
  115. extern struct ax_route *Ax_setups;
  116.  
  117. /* AX.25 Level 3 Protocol IDs (PIDs) */
  118. #define PID_X25        0x01    /* CCITT X.25 PLP */
  119. #define    PID_SEGMENT    0x08    /* Segmentation fragment */
  120. #define PID_TEXNET    0xc3    /* TEXNET datagram protocol */
  121. #define    PID_LQ        0xc4    /* Link quality protocol */
  122. #define    PID_APPLETALK    0xca    /* Appletalk */
  123. #define    PID_APPLEARP    0xcb    /* Appletalk ARP */
  124. #define    PID_IP        0xcc    /* ARPA Internet Protocol */
  125. #define    PID_ARP        0xcd    /* ARPA Address Resolution Protocol */
  126. #define    PID_RARP    0xce    /* ARPA Reverse Address Resolution Protocol */
  127. #define    PID_NETROM    0xcf    /* NET/ROM */
  128. #define    PID_NO_L3    0xf0    /* No level 3 protocol */
  129.  
  130. #define    SEG_FIRST    0x80    /* First segment of a sequence */
  131. #define    SEG_REM        0x7f    /* Mask for # segments remaining */
  132.  
  133. #define    AX_EOL        "\r"    /* AX.25 end-of-line convention */
  134.  
  135. #if 0
  136. /* Link quality report packet header, internal format */
  137. struct lqhdr {
  138.     int16 version;        /* Version number of protocol */
  139. #define    LINKVERS    1
  140.     uint32    ip_addr;    /* Sending station's IP address */
  141. };
  142. #define    LQHDR    6
  143. /* Link quality entry, internal format */
  144. struct lqentry {
  145.     char addr[AXALEN];    /* Address of heard station */
  146.     int32 count;        /* Count of packets heard from that station */
  147. };
  148. #define    LQENTRY    11
  149. #endif
  150.  
  151. /* Link quality database record format
  152.  * Currently used only by AX.25 interfaces
  153.  */
  154. struct lq {
  155.     struct lq *next;
  156.     char addr[AXALEN];    /* Hardware address of station heard */
  157.     struct iface *iface;    /* Interface address was heard on */
  158.     int32 time;        /* Time station was last heard */
  159.     int32 currxcnt;    /* Current # of packets heard from this station */
  160.  
  161. #ifdef    notdef        /* Not yet implemented */
  162.     /* # of packets heard from this station as of his last update */
  163.     int32 lastrxcnt;
  164.  
  165.     /* # packets reported as transmitted by station as of his last update */
  166.     int32 lasttxcnt;
  167.  
  168.     int16 hisqual;    /* Fraction (0-1000) of station's packets heard
  169.              * as of last update
  170.              */
  171.     int16 myqual;    /* Fraction (0-1000) of our packets heard by station
  172.              * as of last update
  173.              */
  174. #endif
  175. };
  176. #define    NULLLQ    (struct lq *)0
  177.  
  178. extern struct lq *Lq;    /* Link quality record headers */
  179.  
  180. /* Structure used to keep track of monitored destination addresses */
  181. struct ld {
  182.     struct ld *next;    /* Linked list pointers */
  183.     char addr[AXALEN];/* Hardware address of destination overheard */
  184.     struct iface *iface;    /* Interface address was heard on */
  185.     int32 time;        /* Time station was last mentioned */
  186.     int32 currxcnt;    /* Current # of packets destined to this station */
  187. };
  188. #define    NULLLD    (struct ld *)0
  189.  
  190. extern struct ld *Ld;    /* Destination address record headers */
  191.  
  192. #ifdef __GNUC__
  193. struct ax25_cb;            /* forward declaration */
  194. #endif
  195.  
  196. /* Linkage to network protocols atop ax25 */
  197. struct axlink {
  198.     int pid;
  199.     void (*funct) (struct iface *,struct ax25_cb *,char *, char *,
  200.      struct mbuf *,int);
  201. };
  202. extern struct axlink Axlink[];
  203.  
  204. /* Codes for the open_ax25 call */
  205. #define    AX_PASSIVE    0
  206. #define    AX_ACTIVE    1
  207. #define    AX_SERVER    2    /* Passive, clone on opening */
  208.  
  209. /* Max number of fake AX.25 interfaces for RFC-1226 encapsulation */
  210. #define NAX25       16
  211.  
  212. #define    AXHEARD_PASS    0    /* Log both src and dest callsigns */
  213. #define    AXHEARD_NOSRC    1    /* do not log source callsign */
  214. #define    AXHEARD_NODST    2    /* do not log destination callsign */
  215. #define    AXHEARD_NONE    3    /* do not log any callsign */
  216.  
  217. /* an call that should not be jump-started */
  218. struct no_js {
  219.     struct no_js *next;
  220.     char call[AXALEN];
  221. };
  222.  
  223. /* AX.25 protocol data kept per interface */
  224. struct ifax25 {
  225.     int paclen;
  226.     int lapbtimertype;
  227.     long irtt;
  228.     int version;
  229.     long t3;
  230.     long t4;
  231.     int n2;
  232.     int maxframe;
  233.     int pthresh;
  234.     int window;
  235.     long blimit;
  236.     long maxwait;   /* maximum backoff time */
  237.     char *bctext;
  238. };
  239.    
  240. /* In ax25.c: */
  241. struct ax_route *ax_add (char *,int,char digis[][AXALEN],int,struct iface *);
  242. int ax_drop (char *,struct iface *, int);
  243. struct ax_route *ax_lookup (const char *source, const char *dest,struct iface *ifp, int type);
  244. void axip_input (struct iface *iface,struct ip *ip,struct mbuf *bp,int rxbroadcast);
  245. void ax_recv (struct iface *,struct mbuf *);
  246. int ax_send (struct mbuf *bp,struct iface *iface,uint32 gateway,int prec,
  247.     int del,int tput,int rel);
  248. int ax_output (struct iface *iface,const char *dest,char *source,int16 pid,
  249.     struct mbuf *data);
  250. int sendframe (struct ax25_cb *axp,int cmdrsp,int ctl,struct mbuf *data);
  251. void axnl3 (struct iface *iface,struct ax25_cb *axp,char *src,
  252.     char *dest,struct mbuf *bp,int mcast);
  253. void axsetupflush (void);
  254.  
  255. /* In ax25cmd.c: */
  256. void st_ax25 (struct ax25_cb *axp);
  257. int axheard (struct iface *ifp);
  258. void init_ifax25 (struct ifax25 *);
  259. int connect_filt (int argc,char *argv[],char target[],struct iface *ifp, int mode);
  260.  
  261. /* In axhdr.c: */
  262. struct mbuf *htonax25 (struct ax25 *hdr,struct mbuf *data);
  263. int ntohax25 (struct ax25 *hdr,struct mbuf **bpp);
  264.  
  265. /* In axlink.c: */
  266. void logsrc (struct iface *iface,char *addr);
  267. void logdest (struct iface *iface,const char *addr);
  268. #if 0
  269. void getlqentry (struct lqentry *ep,struct mbuf **bpp);
  270. void getlqhdr (struct lqhdr *hp,struct mbuf **bpp);
  271. char *putlqentry (char *cp,char *addr,int32 count);
  272. char *putlqhdr (char *cp,int16 version,uint32 ip_addr);
  273. #endif
  274. struct lq *al_lookup (struct iface *ifp,char *addr,int sort);
  275. struct ld *ad_lookup (struct iface *ifp,const char *addr,int sort);
  276.  
  277. /* In ax25user.c: */
  278. int ax25val (struct ax25_cb *axp);
  279. int disc_ax25 (struct ax25_cb *axp);
  280. int kick_ax25 (struct ax25_cb *axp);
  281. struct ax25_cb *open_ax25 (struct iface *,char *,char *,
  282.     int,int16,
  283.     void (*) (struct ax25_cb *,int),
  284.     void (*) (struct ax25_cb *,int),
  285.     void (*) (struct ax25_cb *,int,int),
  286.     int user);
  287. struct mbuf *recv_ax25 (struct ax25_cb *axp,int16 cnt);
  288. int reset_ax25 (struct ax25_cb *axp);
  289. int send_ax25 (struct ax25_cb *axp,struct mbuf *bp,int pid);
  290.  
  291. /* In ax25subr.c: */
  292. int addreq (const char *a,const char *b);
  293. struct ax25_cb *cr_ax25 (char *local,char *remote,struct iface *iface);
  294. void del_ax25 (struct ax25_cb *axp);
  295. struct ax25_cb *find_ax25 (const char *local, const char *remote,struct iface *iface);
  296. char *pax25 (char *e,char *addr);
  297. int setcall (char *out,const char *call);
  298.  
  299. /* In axui.c: */
  300. #ifdef AXUI
  301. int doaxui (int argc, char *argv[],void *p);
  302. void axui_input (struct iface *iface,struct ax25_cb *axp,char *src,char *dest,struct mbuf *bp,int mcast);
  303. #endif
  304.  
  305. /* In socket.c: */
  306. #if 0
  307. void beac_input (struct iface *iface,char *src,struct mbuf *bp);
  308. #endif
  309. void s_arcall (struct ax25_cb *axp,int cnt);
  310. void s_ascall (struct ax25_cb *axp,int old,int new);
  311. void s_atcall (struct ax25_cb *axp,int cnt);
  312.  
  313. #endif    /* _AX25_H */
  314.